#include<bits/stdc++.h>
using namespace std;
#pragma warning(disable:4996)

int n,k;
int arr[10001];
unordered_map<int, int> mp;
int main() {

	scanf("%d %d", &n, &k);
	fill(arr, arr + 10001, -1);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int address, index;
		scanf("%d %d", &address, &index);
		sum += index;
		arr[i] = sum;
		mp[sum] = address;
	}


	int maxarr = 0;
	for (int i = 0; i < k; i++) {
		int a;
		scanf("%d", &a);
		int j;
		for (j = 0; j < n; j++) {
			if (a < arr[j]) {
				if (j == 0) {
					printf("%d\n", mp[arr[j]] + a * 4);
				}
				else {
					printf("%d\n", mp[arr[j]] + (a - arr[j-1]) * 4);
				}
				
				if (maxarr < j) {
					maxarr = j;
				}
				break;
			}
		}
		if (j == n) {
			printf("Illegal Access\n");
		}
	}
	printf("%d", maxarr+1);



	system("pause");
	return 0;
}